package org.nokatag.tagjava;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;

import org.nokatag.password.AESPlus;
import org.nokatag.system.Concest;

public class AccordionTree  extends BodyNokaTag{
	private static final long serialVersionUID = -3150480514983503585L;
	private String id = null; //id
	private String sql = null;//sql
	private String url = null;//url
	private String target = null;//target
	private String formatcell=null;//格式化列
	private String pramevar = null;//参数
	private String spid = null;//上级节点
	private String level= "2";//预加载级数，0为全部加载
	private String titleonclick=null;//标题单击时调用
	private String nodeonclick=null;//节点单击时调用
	private String name =null;//控件名字
	private Boolean titlecliek=true;//节点标题是否响应点击事件
	private String onclick=null;//单击时调用的方法
	private String img = null;
	
	public int doEndTag() throws JspException {
		 StringBuilder stringBuilder = new StringBuilder();
		 HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		 stringBuilder.append(potjs(request));//js框架
		 stringBuilder.append(treejs(request));//tree js
         stringBuilder.append("<li>");
         String imgHtml = "";
         if(img!=null)
        	 imgHtml="<img src=\""+img+"\" style=\"vertical-align:middle;\"/>";
         if(onclick!=null){
        	 stringBuilder.append("<a style=\"display:inline-block;\"onclick=\""+onclick+"\"><h3>"+imgHtml+name+"</h3></a>");
         } else{
        	 stringBuilder.append("<h3>"+imgHtml+name+"</h3>");
         }
         stringBuilder.append("<div class=\"acc-section\">");
         stringBuilder.append("<div class=\"acc-content\">");
         //-----------------------------树形菜单---------------------------------------------
			String sql_s = AESPlus.encrypt(sql, Concest.SQLKEY);//加密sql
			String url_s = (url==null?"":AESPlus.encrypt(url, Concest.SQLKEY));//加密url
			String fc =(formatcell==null?"":AESPlus.encrypt(formatcell, Concest.SQLKEY));//加密formatcell
			String pr =(pramevar==null?"":AESPlus.encrypt(pramevar, Concest.SQLKEY));//加密formatcell
			String tr=(target==null?"":target);
			String sid=(spid==null?"":spid);
			String basePath = basepath(request);
			stringBuilder.append("<div id=\""+id+"_bdiv\" style=\"text-align: left;\">");
			stringBuilder.append("<div id=\""+id+"_tdiv\" class=\"dtree\"></div>");
			stringBuilder.append("</div>");
			stringBuilder.append("<script type=\"text/javascript\">");
			//---------------显示树形菜单---------------------------
			stringBuilder.append("Event.observe(document, 'dom:loaded', function() {");
			stringBuilder.append("var cfg"+id+" = {");
			stringBuilder.append("id:'"+id+"',");//id
			stringBuilder.append("rurl:'"+basePath+"',");//根url
			stringBuilder.append("url:'"+url_s+"',");//url
			stringBuilder.append("level:"+level+",");//预加载级别
			stringBuilder.append("spid:'"+sid+"',");//父id
			stringBuilder.append("sql:'"+sql_s+"',");//sql
			stringBuilder.append("pramevar:'"+pr+"',");//参数
			stringBuilder.append("target:'"+tr+"',");//目标
			stringBuilder.append("formatcell:'"+fc+"',");//格式化列
			stringBuilder.append("inputname:'"+id+"',");//控件名字
			stringBuilder.append("checkname:'"+id+"_check"+"',");//控件名字
			stringBuilder.append("value:'',");//控件初始值
			stringBuilder.append("readonly:'',");//只读
			stringBuilder.append("titlecliek:"+titlecliek+",");//标题是否响应点击事件
			stringBuilder.append("checktype:'',");//级联关系
			stringBuilder.append("titleonclick:function(node){"+(titleonclick==null?"":titleonclick+"(node);")+"},");//单击标题
			stringBuilder.append("nodeonclick:function(node){"+(nodeonclick==null?"":nodeonclick+"(node);")+"},");//单击节点
			stringBuilder.append("checkboxonclick:function(node){return true;}");//单击勾选框
			stringBuilder.append("};");
			stringBuilder.append("var nr"+id+" = new ntree(cfg"+id+");");
			stringBuilder.append("nr"+id+".show();");
			stringBuilder.append("});");
			stringBuilder.append("</script>");
         //---------------------------------------------------------------------------------
         stringBuilder.append("</div>");
         stringBuilder.append("</div>");
         stringBuilder.append("</li>");
		try {
			pageContext.getOut().write(stringBuilder.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		 return SKIP_BODY;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	public String getFormatcell() {
		return formatcell;
	}

	public void setFormatcell(String formatcell) {
		this.formatcell = formatcell;
	}

	public String getPramevar() {
		return pramevar;
	}

	public void setPramevar(String pramevar) {
		this.pramevar = pramevar;
	}

	public String getSpid() {
		return spid;
	}

	public void setSpid(String spid) {
		this.spid = spid;
	}

	public String getLevel() {
		return level;
	}

	public void setLevel(String level) {
		this.level = level;
	}

	public String getTitleonclick() {
		return titleonclick;
	}

	public void setTitleonclick(String titleonclick) {
		this.titleonclick = titleonclick;
	}

	public String getNodeonclick() {
		return nodeonclick;
	}

	public void setNodeonclick(String nodeonclick) {
		this.nodeonclick = nodeonclick;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Boolean getTitlecliek() {
		return titlecliek;
	}

	public void setTitlecliek(Boolean titlecliek) {
		this.titlecliek = titlecliek;
	}

	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}
	
}
